package com.baizhi.service.impl;

import com.baizhi.dao.EmpDao;
import com.baizhi.entity.Emp;
import com.baizhi.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

@Service
@Transactional
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpDao empDao;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Emp> findAll() {
        return empDao.findAll();
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public Emp findById(String id) {
        return empDao.findById(id);
    }

    @Override
    public boolean save(Emp emp) {
        emp.setId(UUID.randomUUID().toString());
        int result = empDao.save(emp);
        return result > 0 ? true : false;
    }

    @Override
    public boolean update(Emp emp) {
        int result = empDao.update(emp);
        return result > 0 ? true : false;
    }

    @Override
    public boolean deleteById(String id) {
        int result = empDao.deleteById(id);
        return result > 0 ? true : false;
    }
}
